<!--&lt;!&ndash; components/VideoCard.vue &ndash;&gt;-->
<!--<template>-->
<!--  <div class="video-card" @click="handleVideoClick">-->
<!--    <div class="cover-container">-->
<!--      &lt;!&ndash; 播放量 &ndash;&gt;-->
<!--      <div class="video-stats">-->
<!--        <span class="play-count">-->
<!--          <el-icon><el-image src="/pic/views.svg"/></el-icon>-->
<!--          {{ formatViews(video.views) }}-->
<!--        </span>-->
<!--      </div>-->

<!--      &lt;!&ndash; 时长显示 &ndash;&gt;-->
<!--      <div class="video-duration">-->
<!--        {{ video.duration }}-->
<!--      </div>-->

<!--      <el-image-->
<!--          :src="video.coverUrl"-->
<!--          class="video-cover"-->
<!--          fit="cover"-->
<!--      >-->
<!--        <template #placeholder>-->
<!--          <div class="skeleton-cover"></div>-->
<!--        </template>-->
<!--      </el-image>-->
<!--      <div class="cover-hover">-->
<!--        <el-icon :size="40" color="#fff"><VideoPlay/></el-icon>-->
<!--      </div>-->
<!--    </div>-->

<!--    <div class="video-info">-->
<!--      <h3 class="title">{{ video.title }}</h3>-->
<!--      <div class="meta-line">-->
<!--        <span class="author">-->
<!--          <el-icon><User/></el-icon>-->
<!--          {{ video.nickname }}-->
<!--        </span>-->
<!--        <span class="date">-->
<!--          {{ formatViews(video.createdAt) }}-->
<!--        </span>-->
<!--      </div>-->
<!--    </div>-->
<!--  </div>-->
<!--</template>-->

<!--<script setup>-->
<!--import { defineProps, defineEmits } from 'vue'-->
<!--import { View, VideoPlay, User } from '@element-plus/icons-vue'-->

<!--const props = defineProps({-->
<!--  video: Object-->
<!--})-->

<!--const emit = defineEmits(['videoClick'])-->

<!--const formatViews = (num) => {-->
<!--  if (num > 10000) return `${(num / 10000).toFixed(1)}万`-->
<!--  if (num > 1000) return `${(num / 1000).toFixed(1)}千`-->
<!--  return num-->
<!--}-->

<!--const handleVideoClick = () => {-->
<!--  emit('videoClick', props.video)-->
<!--}-->
<!--</script>-->

<!--<style lang="scss" scoped>-->
<!--.video-card {-->
<!--  background: #fff;-->
<!--  border-radius: 8px;-->
<!--  overflow: hidden;-->
<!--  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);-->
<!--  margin-bottom: 8px;-->

<!--  &:hover {-->
<!--    transform: translateY(-4px);-->

<!--  }-->
<!--}-->


<!--.cover-container {-->
<!--  position: relative;-->
<!--  .video-duration {-->
<!--    position: absolute;-->
<!--    bottom: 8px;-->
<!--    right: 8px;-->
<!--    padding: 2px 6px;-->

<!--    color: #fff;-->

<!--    font-size: 12px;-->
<!--    z-index: 2;-->

<!--  }-->
<!--}-->

<!--/* 调整播放量样式避免重叠 */-->
<!--.video-stats {-->
<!--  left: 8px;-->
<!--  bottom: 8px;-->
<!--  right: auto;-->
<!--  background: none;-->
<!--  padding: 0;-->

<!--  .play-count {-->
<!--    padding: 2px 6px;-->

<!--    border-radius: 4px;-->
<!--    font-size: 12px;-->
<!--  }-->
<!--}-->
<!--/* 播放量样式 */-->
<!--.video-stats {-->
<!--  position: absolute;-->
<!--  bottom: 0;-->
<!--  left: 0;-->
<!--  right: 0;-->
<!--  padding: 8px;-->
<!--  background: linear-gradient(0deg, rgba(0,0,0,0.6) 0%, transparent 100%);-->
<!--  color: #fff;-->
<!--  z-index: 1;-->
<!--  display: flex;-->
<!--  align-items: center;-->
<!--  font-size: 20px;-->

<!--  .play-count {-->
<!--    display: flex;-->
<!--    align-items: center;-->
<!--    gap: 4px;-->

<!--    .el-icon {-->
<!--      font-size: 14px;-->
<!--    }-->
<!--  }-->
<!--}-->

<!--/* 优化封面容器 */-->
<!--.cover-container {-->
<!--  position: relative;-->
<!--  width: 100%;-->
<!--  aspect-ratio: 16/9;-->
<!--  background: #f5f7fa;-->
<!--  overflow: hidden;-->
<!--  border-radius: 8px;-->

<!--  .video-cover {-->
<!--    width: 100%;-->
<!--    height: 100%;-->
<!--    object-fit: cover;-->
<!--    transition: transform 0.3s;-->
<!--    border-radius: 8px;-->
<!--  }-->

<!--  &:hover .video-cover {-->
<!--    transform: scale(1.05);-->
<!--  }-->
<!--}-->

<!--/* 调整文字大小间距 */-->
<!--.video-info {-->
<!--  padding: 12px;-->

<!--  .title {-->
<!--    font-size: 20px;-->
<!--    line-height: 20px;-->
<!--    margin: 8px 0; // 增加上下间距-->
<!--  }-->

<!--  .meta-line {-->
<!--    margin-top: 12px; // 增加间距-->
<!--  }-->
<!--  .author{-->
<!--    font-size: 15px;-->
<!--    color: #9499a0;-->


<!--  }-->
<!--  .date{-->
<!--    margin-left: 8px ;-->
<!--    font-size: 15px;-->
<!--color: #9499a0;-->

<!--  }-->

<!--}-->

<!--@media (max-width: 768px) {-->
<!--  .video-info {-->
<!--    padding: 8px;-->

<!--    .title {-->
<!--      font-size: 13px;-->
<!--      line-height: 18px;-->
<!--      margin: 6px 0;-->
<!--    }-->
<!--  }-->
<!--}-->
<!--</style>-->

<!--<style lang="scss" scoped>-->
<!--.video-info {-->
<!--  .title {-->
<!--    display: -webkit-box;-->
<!--    -webkit-line-clamp: 2;-->
<!--    -webkit-box-orient: vertical;-->
<!--    overflow: hidden;-->
<!--    height: 40px;-->
<!--    line-height: 20px;-->
<!--  }-->

<!--  .meta-line {-->
<!--    display: flex;-->
<!--    justify-content: space-between;-->
<!--    align-items: center;-->
<!--    margin-top: 8px;-->
<!--  }-->
<!--}-->

<!--.video-duration {-->
<!--  background: rgba(0,0,0,0.7);-->
<!--  border-radius: 4px;-->
<!--  text-shadow: 0 1px 2px rgba(0,0,0,0.3);-->
<!--}-->

<!--.video-stats {-->
<!--  .play-count {-->
<!--    background: rgba(0,0,0,0.5);-->
<!--    backdrop-filter: blur(2px);-->
<!--    box-shadow: 0 2px 4px rgba(0,0,0,0.1);-->
<!--  }-->
<!--}-->

<!--.date {-->
<!--  color: #666;-->

<!--}-->
<!--</style>-->

<template>
  <div class="video-card" @click="handleVideoClick">
    <div class="cover-container">
      <el-image
          :src="video.coverUrl"
          class="video-cover"
          fit="cover"
      >
        <template #error>
          <div class="image-error">
            <i class="el-icon-picture-outline"></i>
          </div>
        </template>
      </el-image>
      <div class="video-duration">{{ video.duration }}</div>
      <div class="video-views">
        <i class="el-icon-view"></i>
                  <el-icon><el-image src="/pic/views.svg"/></el-icon>

        {{ formatViews(video.views) }}
      </div>
    </div>
    <div class="video-info">
      <h3 class="video-title">{{ video.title }}</h3>
      <div class="video-meta">
        <span class="author">{{ video.nickname }}</span>
        <span class="date">{{ video.createdAt }}</span>
      </div>
    </div>
  </div>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue';

const props = defineProps({
  video: {
    type: Object,
    required: true
  }
});

// 兼容@videoClick和@click
const emit = defineEmits(['videoClick', 'click']);

const formatViews = (views) => {
  if (views >= 10000) {
    return (views / 10000).toFixed(1) + '万';
  }
  return views;
};

const formatDate = (dateString) => {
  const date = new Date(dateString);
  const now = new Date();
  const diffDays = Math.floor((now - date) / (1000 * 60 * 60 * 24));

  if (diffDays === 0) return '今天';
  if (diffDays === 1) return '昨天';
  if (diffDays < 7) return `${diffDays}天前`;

  return date.toLocaleDateString('zh-CN', {
    month: '2-digit',
    day: '2-digit'
  });
};

const handleVideoClick = () => {
  emit('videoClick', props.video);
  emit('click', props.video);
};
</script>

<style scoped>
.video-card {
  background-color: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
  cursor: pointer;
}

.video-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1);
}

.cover-container {
  position: relative;
  width: 100%;
  padding-top: 56.25%; /* 16:9 Aspect Ratio */
  overflow: hidden;
}

.video-cover {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 8px 8px 0 0;
}

.image-error {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background-color: #f5f7fa;
  color: #909399;
  font-size: 24px;
}

.video-duration {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background-color: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 3px 6px;
  border-radius: 4px;
  font-size: 12px;
}

.video-views {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background-color: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 3px 6px;
  border-radius: 4px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.video-info {
  padding: 12px;
}

.video-title {
  font-size: 14px;
  line-height: 1.4;
  margin: 0 0 8px 0;
  height: 40px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  font-weight: 500;
}

.video-meta {
  display: flex;
  justify-content: space-between;
  color: #999;
  font-size: 12px;
}

.author {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 70%;
}
</style>
